// pages/time/time.js
const { oneOptions, twoOptions, threeOptions, sixOptions, transformOptions } = require('./config')

Page({
  /**
   * 页面的初始数据
   */
  data: {
    oneOptions: transformOptions(oneOptions),
    twoOptions: transformOptions(twoOptions),
    threeOptions: transformOptions(threeOptions),
    sixOptions: transformOptions(sixOptions),
    ones: [],
    twos: [],
    threes: [],
    sixs: [],
    // 宝牌数
    dora: 0,
    // 赤宝牌数
    redDora: 0,
    // 里宝牌数
    innerDora: 0,
    chied: false,
  },
  setOnes(evet) {
    this.setData({
      ones: evet.detail,
    })
  },
  setTwos(evet) {
    this.setData({
      twos: evet.detail,
    })
  },
  setThrees(evet) {
    this.setData({
      threes: evet.detail,
    })
  },
  setSixs(evet) {
    this.setData({
      sixs: evet.detail,
    })
  },
  handleSumbit() {
    const { ones, twos, threes, sixs, dora, redDora, innerDora, chied } = this.data;
    let result = ones.length + twos.length * 2 + threes.length * 3 + sixs.length * 6 + dora + redDora + innerDora;
    // 副露了
    if (chied) {
      // 三色同顺、一气通贯、混全
      if (twos.includes('三色同顺')) {
        result--;
      }
      if (twos.includes('一气通贯')) {
        result--;
      }
      if (twos.includes('混全带幺九')) {
        result--;
      }
      if (threes.includes('混一色')) {
        result--;
      }
      if (threes.includes('纯全带幺九')) {
        result--;
      }
      if (sixs.includes('清一色')) {
        result--;
      }
    }
    const eventChannel = this.getOpenerEventChannel()
    eventChannel.emit('link', result);
    wx.navigateBack();
  },
})